module.exports = class  extends baseController {
    constructor(){
        super();
        this.markdownIt = require('markdown-it')();
        this.router.get('/:fileName', this.getMDFile.bind(this));
        return this.router;
    }

    static init() {
        return new this();
    }

    getMDFile(req,res,next){
        try{
            let fs=require('fs');
            let tmp = require('../views/doc.marko');
            let FileName = req.params.fileName;
            let FilePath = __dirname + "/../doc/" + FileName+".md";
            let content = fs.readFileSync(FilePath, 'utf-8');
            let data = {
                viewData: {
                   // content:this.markdownIt.utils.unescapeAll(this.markdownIt.render(content))
                   content:this.markdownIt.render(content),
                   docMenu:require('../static/scripts/doc-menus.json'),
                   fileName:FileName.toLowerCase()
                }
            };
            tmp.render(data, res);
        }catch (err) {
            next(err);
        }

    }
};
